<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="wrapper">
        <div class="content"></div>
    </div>
</body>
<style>
    /* 方法一 */
    .wrapper {
        background-color: #eee;
        width: 200px;
        height: 200px;
        position: relative;
    }

    .wrapper .content {
        width: 50px;
        height: 50px;
        background-color: forestgreen;
        position: absolute;
        margin: auto;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    /* 方法二 */
    .wrapper {
        background-color: #eee;
        width: 200px;
        height: 200px;
        position: relative;
        margin-top: 20px;
    }

    .wrapper .content {
        width: 50px;
        height: 50px;
        background-color: rgb(34, 71, 139);
        position: absolute;
        left: 50%;
        top: 50%;
        margin-left: -25px;
        margin-top: -25px;
    }

    /* 方法三 */
    .content {
        width: 50px;
        height: 50px;
        background-color: rgb(34, 71, 139);
        position: absolute;
        left: calc(50% - 25px);
        top: calc(50% - 25px);
    }
</style>

</html>